<?php

namespace app\common\model;

/**
 * [GoodsGroup  拼团表]
 * @author [C。]
 * @return html
 */
class GoodsGroup extends Base
{
    protected $name = 'goods_group';

    /**
     * 根据搜索条件获取列表信息
     */
    public function getList($map, $from = 0, $size = 5, $field = '*')
    {
        $order = ['g.id' => 'desc'];
        $join1 = [
            ['app_member m','m.id = o.memid'],
        ];
        $join2 = [
            ['app_order o','o.id = g.orderid'],
        ];
        $join3 = [
            ['app_goods_option go','go.id = o.optionid'],
        ];
        $result = $this->field($field)
            ->alias('g')
            ->join($join2)
            ->join($join1)
            ->join($join3)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getCount($map)
    {
        $join1 = [
            ['app_member m','m.id = o.memid'],
        ];
        $join2 = [
            ['app_order o','o.id = g.orderid'],
        ];
        $join3 = [
            ['app_goods_option go','go.id = o.optionid'],
        ];
        $result = $this
            ->alias('g')
            ->join($join2)
            ->join($join1)
            ->join($join3)
            ->where($map)
            ->count();

        return $result;
    }

    /**
     * 根据搜索条件获取列表信息
     */
    public function getrefund($map, $from = 0, $size = 5, $field = '*')
    {
        $order = ['g.id' => 'desc'];
        $join1 = [
            ['app_order o','o.groupid = g.id'],
        ];
        $join2 = [
            ['app_goods_option go','go.id = o.optionid'],
        ];
        $result = $this->field($field)
            ->alias('g')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getrefundcount($map)
    {
        $join1 = [
            ['app_order o','o.groupid = g.id'],
        ];
        $join2 = [
            ['app_goods_option go','go.id = o.optionid'],
        ];
        $result = $this->alias('g')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->count();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getLists($map,$field = '*')
    {
        $order = ['g.id' => 'desc'];
        $join1 = [
            ['app_member m','m.id = ao.memid'],
        ];
        $join2 = [
            ['app_goods_option o','o.id = ao.optionid'],
        ];
        $join3 = [
            ['app_order ao','ao.id = g.orderid'],
        ];
        $result = $this->field($field)
            ->alias('g')
            ->join($join3)
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->order($order)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function lists($goodsid,$time1,$time2)
    {
        $sql = "SELECT * FROM app_goods_group as g,app_order as o,app_member as m WHERE m.id = g.memid AND o.group_id = g.id AND g.goodsid = $goodsid AND g.addtime BETWEEN $time1 AND $time2 AND o.refundid = 0 AND o.option_personnum > (select sum(num) from app_order where (status = 1) or (status = 0 and )) ";
    }
}